package com.mach.platform.domain;

import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Administrator
 * @Description:  能源 架构
 * @Package: com.mach.platform.domain
 * @time 2018/10/19 0019 14:16
 */
@Entity
@Data
@Table(name = "energy_struc")
public class EnergyStruc implements Serializable {

	private static final long serialVersionUID = -2009794371215732533L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	/**
	 * 能源类型
	 */
	private String type;

	/**
	 * 父级
	 */
	private Long pid;

	/**
	 * 名称
	 */
	private String name;

	/**
	 * 所属工厂
	 */
	private String factory;

	/**
	 * 层级
	 * 从 1 为顶级开始
	 */
	private Integer level;

	/**
	 * 排序
	 */
	@Column(name = "sort", columnDefinition = "tinyint default 1")
	private Integer sort;


	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "energy_struc_id")
	private List<EnergyStrucProp> props = Collections.EMPTY_LIST;


	@Transient
	private boolean expand = false;

	@Transient
	private String label;

	@Transient
	private Long value;

	@Transient
	private List<EnergyStruc> children = new ArrayList<>();

	public String getLabel ( ) {
		return this.name;
	}

	public Long getValue ( ) {
		return this.id;
	}
}
